package com.reggie.mapper;

import com.reggie.dto.SetmealDto;
import com.reggie.pojo.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {
    List<Setmeal> findAll(Integer page, Integer pageSize, String name);

    @Update("UPDATE setmeal SET is_deleted=1, update_user=#{userId}, update_time=now() WHERE id=#{id}")
    int delete(Long id, Long userId);

    @Update("UPDATE setmeal SET status=#{status}, update_time=now(), update_user=#{userId} WHERE id=#{id}")
    Integer editStatus(Long id, Integer status, Long userId);

    @Insert("INSERT INTO setmeal (id, category_id, name, price, status, code, description, image, create_time, update_time, create_user, update_user, is_deleted) " +
            "values (#{id}, #{categoryId}, #{name}, #{price}, 1, #{code}, #{description}, #{image}, now(), now(), #{createUser}, #{updateUser}, 0)")
    Integer add(SetmealDto setmealDto);

    @Select("SELECT * FROM setmeal WHERE id=#{id}")
    SetmealDto find(Long id);

    @Update("UPDATE setmeal SET category_id=#{categoryId}, name=#{name}, price=#{price}, description=#{description}, image=#{image}, update_time=now(), update_user=#{updateUser} " +
            "WHERE id=#{id}")
    Integer edit(SetmealDto setmealDto);

    @Select("SELECT * FROM setmeal WHERE category_id=#{categoryId} and status=#{status}")
    List<Setmeal> findByCategoryIdAndStatus(Long categoryId, Integer status);
}
